from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api import router as api_router

app = FastAPI(
    title="PeiYangGuide API",
    description="活动报名和表单管理系统的API",
    version="1.0.0",
)

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 在生产环境中应该限制来源
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(api_router, tags=["活动"])

@app.get("/")
async def root():
    return {"message": "欢迎使用PeiYangGuide API"}


def run():
    import uvicorn

    load_dotenv()
    for route in app.routes:
        print(route)
    uvicorn.run(app, host="127.0.0.1", port=8080)
    # cmd
    # uvicorn app.main:app --reload --port 8080


# 启动应用
if __name__ == "__main__":
    import uvicorn

    uvicorn.run("app.main:app", host="0.0.0.0", port=8080, reload=True)
